var vm = new Vue({
    //vue对象节点,指向父盒子
    el:'#place',                                                            
    //vue实例 的data属性
    data:function(){
        return{
        	pageA:true,
        	tableData:[],
        	newFlag:false,
        	pageB:false,
        	model:{},
	    	modelRules:{ 
	   	    	iname: [{ required: true, message: '请填写', trigger: 'blur' }],
	   	    },
        	//分页条
  	        pageSize:10,
  	        currPage:1,
  	        total:1,
  	        lostEditorEdit:null,
  	        multipleSelection:[]
        }
    },
    //vue实例 的methods
    methods:{
    	handleSizeChange:function(val) {
            vm.pageSize = val;
            vm.loadData();
         },
         handleCurrentChange:function(val) {
      	   vm.currPage = val;
      	   vm.loadData();
         },
         handleSelectionChange(val) {
             vm.multipleSelection = val;
         },
         //格式化日期
         statusFormat:function(row,column){
      	   return '正常';
         },
         loadData:function(){

      	   var url = "./listItemByPage.action";

      	   var params = {
      			 "pagemap.page":vm.currPage,
      			 "pagemap.size":vm.pageSize,
      	   }
      	   pb.ajaxPost(url,params,function(r){
  	       		if(r.code == '000000'){
  	       			vm.tableData = r.itemTypes;
  	       			vm.total = r.itemcount;
  	       		}else{
                 		pb.alertErr("加载失败");
                 	}
  	       },function(err){
  	    	   pb.alertErr("加载失败");
  	       });
         },
         getRecord(id){
           if(vm.multipleSelection != null && vm.multipleSelection.length!==1){
        	   pb.alertWar('请选择一条记录');
        	   return;
           }
      	   var url = "./selectItemByPrimary.action";
      	   var params = {
      		   'itemType.iid':vm.multipleSelection[0].iid
      	   }
      	   pb.ajaxPost(url,params,function(r){
  	       		if(r.code == '000000'){
  	       			vm.model = r.item;
  	       		}else{
  	       		 pb.alertErr('获取信息失败');
  	       		}
  	       },function(err){
  	    	   pb.alertErr('获取信息失败');
  	       });
         },
         add:function(){
        	 vm.pageA =false;
        	 vm.pageB =true;
        	 
         },
         update:function(){
        	 vm.pageA =false;
        	 vm.pageB =true;
        	 vm.getRecord();
         },
         //删除
         del:function(){
      	   var ids = [];
	       for(var i=0;i<vm.multipleSelection.length;i++){
	  		   ids.push(vm.multipleSelection[i].iid);
	  	   }
      	   vm.$confirm('确定删除么?','提示',{
                 confirmButtonText: '确定',
                 cancelButtonText: '取消',
                 type:'warning',
                 callback:function(e){
                     if(e === 'confirm'){
                  	   var params = {
                  		   "res.ids":JSON.stringify(ids)
                  	   }
                         pb.ajaxPost("./deleteItem.action",params,function(res){
                             if(res.code == '000000'){
                          	   pb.alertSuc('删除成功');
                               vm.loadData();
                             }else{
                             	pb.alertErr('删除失败');
                             }
                         });
                     	
                     }
                 }
             });
         },
         submit:function(formName){
      	   vm.$refs[formName].validate(function(valid) {
   	          if (valid) {
                    var url ="";
   	        	  if(vm.model.iid == null || vm.model.iid == ''){
   	        		 url = './saveItem.action';
   	        	  }else{
   	        		 url = './updateItem.action';
   	        	  }
                    var params = {
                  		"itemType.iid":vm.model.iid,
                  		"itemType.istatus":vm.model.istatus,
                  		"itemType.iname":vm.model.iname
                    };
                    pb.ajaxPost(url,params,function(r){
                    	if(r.code == '000000'){
                    		pb.alertSuc("提交成功");
                    		vm.back('modelRef');
                    	}else{
                    		pb.alertErr("提交失败");
                    	}
                    	},function(err){

                    		pb.alertErr("操作超时");
                    });
	   	          } else {
	   	            return false;
	   	          }
	   	    });
         },
         back:function(formName){
      	   vm.pageA=true;
      	   vm.pageB=false;
      	   vm.model = {};
      	   vm.$refs[formName].resetFields();
      	   vm.loadData();
         },

    }
    //vue实例 的methods结束
});
vm.loadData();